package com.android.functionmanagement.ui;

import com.android.functionmanagement.BaseActivity;
import com.android.functionmanagement.globle.ConstantGloble;
import com.android.functionmanagement.util.DeviceUtils;
import com.android.functionmanagement.util.SharedPreferencesUtils;
import com.android.functionmanagement.util.ZXingUtil;
import com.uwatch.helowin.R;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author fmh 二维码界面
 * 
 */
public class ZCodeActivity extends BaseActivity {
	private TextView imei, userName;
	private final static String UNBIND = "未绑定";
	private final static String BIND = "绑定用户:";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zcode_layout);
		ImageView zcode = (ImageView) findViewById(R.id.zcode);
		imei = (TextView) findViewById(R.id.imei);
		userName = (TextView) findViewById(R.id.userName);
		zcode.setImageBitmap(ZXingUtil.createQRImage(
				"uwatch:" + DeviceUtils.getIMEI(this),
				DeviceUtils.getDisplayWidth(this),
				DeviceUtils.getDisplayWidth(this)));
		imei.setText("IMEI:" + DeviceUtils.getIMEI(this));
		if (TextUtils.isEmpty(SharedPreferencesUtils.getParam(this,
				ConstantGloble.USERNAME, "").toString())) {
			userName.setText(UNBIND);
		} else {
			userName.setText(BIND
					+ SharedPreferencesUtils.getParam(this,
							ConstantGloble.USERNAME, "").toString());
		}
	}

	protected void updateDisplayData() {
		if (UNBIND.equals(userName.getText())) {
			Toast.makeText(this, "绑定成功", Toast.LENGTH_SHORT).show();
		} else if (!userName.getText().equals(
				SharedPreferencesUtils.getParam(this, ConstantGloble.USERNAME,
						"").toString())) {
			Toast.makeText(this, "切换用户成功", Toast.LENGTH_SHORT).show();
		}
		userName.setText(BIND
				+ SharedPreferencesUtils.getParam(this,
						ConstantGloble.USERNAME, "").toString());
		sendBroadcast(new Intent(
				"android.intent.action.uwatch.REQUEST_USERINFO"));
	}

}
